package xuanke;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import java.awt.Font;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.util.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.awt.event.ActionEvent;
import xkdaima.*;
import java.awt.Color;

public class Coursewhce extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JTextField textField_1;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Coursewhce frame = new Coursewhce();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Coursewhce() {
		setResizable(false);
		setTitle("课程维护设置(自定义)");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(535, 200, 488, 371);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		this.setIconImage(new ImageIcon("Img/36.png").getImage());
		
		textField = new JTextField();
		textField.setBounds(172, 125, 250, 25);
		contentPane.add(textField);
		textField.setColumns(10);
		
		textField_1 = new JTextField();
		textField_1.setBounds(172, 211, 250, 25);
		contentPane.add(textField_1);
		textField_1.setColumns(10);
		
		JLabel lblNewLabel = new JLabel("\u7EF4\u62A4\u5F00\u59CB\u65F6\u95F4");
		lblNewLabel.setFont(new Font("楷体", Font.PLAIN, 17));
		lblNewLabel.setBounds(57, 119, 105, 35);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("\u7EF4\u62A4\u7ED3\u675F\u65F6\u95F4");
		lblNewLabel_1.setFont(new Font("楷体", Font.PLAIN, 17));
		lblNewLabel_1.setBounds(57, 207, 105, 30);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("\u65F6\u95F4\u586B\u5199\u683C\u5F0F\uFF1Ayyyy-MM-dd-HH-mm-ss");
		lblNewLabel_2.setForeground(Color.RED);
		lblNewLabel_2.setFont(new Font("楷体", Font.PLAIN, 19));
		lblNewLabel_2.setBounds(71, 31, 351, 41);
		contentPane.add(lblNewLabel_2);
		
		JButton btnNewButton = new JButton("\u786E\u5B9A");
		btnNewButton.setFont(new Font("楷体", Font.PLAIN, 17));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(textField.getText().equals("")||textField_1.getText().equals(""))
				{
					JOptionPane.showMessageDialog(null,"请填写信息","消息提示",JOptionPane.WARNING_MESSAGE);
				}
				else {
					MCThread mcthread=new MCThread(textField.getText(), textField_1.getText());
					
					SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
			        Calendar calendar = Calendar.getInstance();
			        Date date = calendar.getTime();
			        String systemtime = sdf.format(date);
					if(mcthread.judgedate(textField.getText())||mcthread.judgedate(textField_1.getText())){
			            if(mcthread.comparedate(textField.getText(), textField_1.getText())&&mcthread.comparedate(systemtime, textField_1.getText())){
			                mcthread.start();
			                JOptionPane.showMessageDialog(null,"课程维护开放","消息提示",JOptionPane.INFORMATION_MESSAGE);
			            }
			            else{
			            	JOptionPane.showMessageDialog(null,"维护结束时间必须大于开始时间和系统时间！","消息提示",JOptionPane.WARNING_MESSAGE);
			            }
			        }
			        else{
			        	JOptionPane.showMessageDialog(null,"维护开始时间或者结束时间格式不正确！","消息提示",JOptionPane.WARNING_MESSAGE);
			        }
				}
					
			}
		});
		btnNewButton.setBounds(185, 271, 100, 40);
		btnNewButton.setContentAreaFilled(false);//设置按钮透明
		//btnNewButton.setBorder(null);//取消边框
		contentPane.add(btnNewButton);
		
		Image img = new ImageIcon("Img/25.jpg").getImage();//加载背景图片
		img = img.getScaledInstance(  488, 371, 0);  //设置图片大小
		JLabel label = new JLabel();  //定义一个标签用于存放图片
		label.setBounds(0,0,  488, 371);   
		label.setIcon(new ImageIcon(img));       
		contentPane.add(label);//设置标签大小
	}
}
